#####
# VERY simple boot loader or X86 machines
# Taken almost verbatim from: 
#   http://www.websofia.com/2011/10/writing-your-own-boot-loader-for-a-toy-operating-system-1/
# This file contains the second stage boot loader, which should be stored in the root
# directory in the file 2NDSTAGE.BIN
# Programmer: Pete Lutz
# Date: 5-10-2012
#####
		.code16
		.intel_syntax noprefix
		.text
		.org 0x0             

		.include "macros.s"

		.global main

main:
		xchg bx, bx		# nop of sorts used by a debugger to
					# indicate a 'magic' breakpoint
		mWriteString msg	# Write Hello WOrld message
hang:
		jmp hang		# hang forever

		# 
		# Booting has failed because of a disk error. 
		# Inform the user and reboot.
		# 
bootFailure:
		mWriteString diskerror	# on disk failure write a message
		mReboot			# then reboot the system
		  
		.include "functions.s"

		# PROGRAM DATA
msg:		.asciz	"If you see this, the 2nd stage bootloader has started ...\r\n"
rebootmsg:	.asciz	"Press any key to reboot.\r\n"
diskerror:	.asciz	"Disk error. "

		# Not sure why this is here ... normally read in during 1st stage boot.
		# I can only assume it is here to define labels used in the macros and
		# functions that are no longer needed, but must be there syntactically
		.include "bootsector.s"

		.fill 1024, 1, 1	# Pad 1K with 1-bytes to test file larger than 1 sector
